package com.huawei.org.service.impl;

import com.huawei.basic.service.impl.BaseServiceImpl;
<<<<<<< HEAD
import com.huawei.basic.utils.MD5Utils;
import com.huawei.basic.utils.StrUtils;
import com.huawei.org.domain.Employee;
import com.huawei.org.mapper.EmployeeMapper;
import com.huawei.org.service.IEmployeeService;
import com.huawei.user.domain.Logininfo;
import com.huawei.user.mapper.LogininfoMapper;
import org.springframework.beans.BeanUtils;
=======
import com.huawei.org.domain.Employee;
import com.huawei.org.mapper.EmployeeMapper;
import com.huawei.org.service.IEmployeeService;
>>>>>>> 815a078707a159f81958d10b606db1f81992e9cf
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @Description: 员工的service层实现类
* @Author: huawei
* @Version: 1.0
* @Date:  2022/4/19 18:28
*/
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
<<<<<<< HEAD
    @Autowired
    private LogininfoMapper logininfoMapper;

    // 基础的CRUD方法从公共接口继承而来

    // 模块自己特有的方法或者CRUD实现不一样时写在这里
=======
>>>>>>> 815a078707a159f81958d10b606db1f81992e9cf


    @Override
    public void save(Employee employee) {
<<<<<<< HEAD
        initEmployee(employee);
        Logininfo logininfo = employee2Logininfo(employee);
        logininfoMapper.save(logininfo);//返回自增Id
        employee.setLogininfo_id(logininfo.getId());
        employeeMapper.save(employee);

        //inintRelationTable(employee);
    }

    private void inintRelationTable(Employee employee) {
        // 1.删除历史数据
        // 2.保存新的数据

    }

    private Logininfo employee2Logininfo(Employee employee) {
        Logininfo logininfo = new Logininfo();
        BeanUtils.copyProperties(employee,logininfo);
        logininfo.setType(0);//一定要设置type
        return logininfo;
    }

    private void initEmployee(Employee employee) {
        String salt = StrUtils.getComplexRandomString(32);
        String md5pwd = MD5Utils.encrypByMd5(employee.getPassword() + salt);
        employee.setSalt(salt);//加密的时候使用的盐值保存到数据
        employee.setPassword(md5pwd);//加密之后的密码，保存到数据库
    }


=======
        super.save(employee);
    }

>>>>>>> 815a078707a159f81958d10b606db1f81992e9cf
    @Override
    public void update(Employee employee) {
        super.update(employee);
    }

    @Override
    public void remove(Long id) {
        super.remove(id);
    }
<<<<<<< HEAD

    @Override
    public Employee loadByLogininfoId(Long id) {

        return employeeMapper.loadByLogininfoId(id);
    }
=======
>>>>>>> 815a078707a159f81958d10b606db1f81992e9cf
}
